#!/usr/bin/bash

if [ `whoami` == 'root' ] ; then
echo Комманда не для root.
exit
fi

I2GDIR=`mktemp -d /tmp/install2gisXXXXXXX`
#I2GDIR=/tmp/install2gis
wget 'http://help.2gis.ru/linux/' -O $I2GDIR/install2gis.html
cat $I2GDIR/install2gis.html | grep http://download.2gis.ru/arhives/2GIS | sed -e "s|^.*href='||" | sed -e "s|orig.zip.*$|orig.zip|" > $I2GDIR/install2gis.list

cd /home/`whoami`
#mkdirhier .local/share/icons
#wget $SITE$GISICON -O .local/share/icons/$GISICON
RC=`cat .install2gis.rc`
cd $I2GDIR/
#wget -ic $I2GDIR/install2gis.list
wget -c `cat $I2GDIR/install2gis.list |grep Shell`
for orig in $RC; do
echo $orig
wget -c `cat $I2GDIR/install2gis.list |grep $orig`
done

cd /home/`whoami`
rm -rf '.wine/drive_c/Program Files/2gis'
mkdirhier '.wine/drive_c/Program Files'

cd '.wine/drive_c/Program Files'
for fil in `ls $I2GDIR/*.zip`; do
unzip -o $fil
done

# Десктоп-файл
mkdirhier /home/`whoami`/.local/share/applications
cat > /home/`whoami`/.local/share/applications/2gis3.desktop <<EOF
[Desktop Entry]
Name=ДубльГИС 3.0
Exec=env WINEPREFIX="/home/`whoami`/.wine" wine "C:\Program Files\2gis\3.0\grym.exe" -nomta
Type=Application
StartupWMClass=Wine
Path=/home/`whoami`/.wine/drive_c/Program Files/2gis/3.0/
Categories=Wine
Icon=grym
EOF

rm -rf $I2GDIR

